package com.opennews.openplatform.security;

import com.opennews.openplatform.myspringbootcore.dto.RequestMap;
import com.opennews.openplatform.myspringbootcore.security.RequestMapQuery;
import lombok.RequiredArgsConstructor;
import org.jooq.DSLContext;
import org.springframework.stereotype.Component;

import java.util.List;

import static com.opennews.openplatform.entity.Tables.REQUEST_MAP;

@RequiredArgsConstructor
@Component
public class SecurityRequestMapQuery implements RequestMapQuery {
    private final DSLContext dslContext;

    @Override
    public List<RequestMap> queryAll() {
        return dslContext.selectFrom(REQUEST_MAP).fetch().map(record -> RequestMap.builder()
                .configAttribute(record.getConfigAttribute())
                .httpMethod(record.getHttpMethod())
                .url(record.getUrl())
                .build()
        );
    }
}